<?php

namespace App\Http\Controllers\Purchase;

use App\Http\Controllers\BaseController;
use App\Models\Purchase\PurchasePayOrder;
use Illuminate\Http\Request;


/**
 * 付款单
 */
class PurchasePayOrderController extends BaseController
{
    /**
     * 付款单列表-钉钉回调
     */
    public function getorderlist(Request $request)
    {

        $cpid = $this->mangerinfo['cpid'];
        $manger_id = $this->mangerinfo['id'];
        if ($this->mangerinfo['utype'] == 4) {
            $manger_id = 0; //查询所有订单
        }
        $list = PurchasePayOrder::getList($request, $cpid, $manger_id);
        return response()->json(['code' => '000', 'msg' => '操作成功', 'data' => $list]);
    }

    /**
     * 获取付款单详情
     *
     */
    public function getinfo(Request $request)
    {
        $cpid = $this->mangerinfo['cpid'];
        $manger_id = $this->mangerinfo['id'];
        $id = $request->id ?? 0;
        $info = PurchasePayOrder::where(['cpid' => $cpid, 'manger_id' => $manger_id, 'is_del' => 1, 'id' => $id])->first();
        if (!$info) {
            return response()->json(['code' => '001', 'msg' => '无效参数']);
        }

        return response()->json(['code' => '000', 'msg' => '操作成功', 'data' => ['info' => $info->toArray()]]);
    }
}
